

#include <swarm.h>

#include <time.h>
#include <stdlib.h>


double _sw_rand_max = 100.0;  // Default rand max.
double _sw_rand_min = 0.0;    // Default rand min.

int sw_init_rand(double min, double max){

  if (min >= max) return 1;

  sw_srand(time(NULL));
  _sw_rand_min = min;
  _sw_rand_max = max;

  return 0;

}

double sw_random(){

  double start = (double) random();
  double scale = (_sw_rand_max - _sw_rand_min) / (double) RAND_MAX;

  return (start * scale) + _sw_rand_min;

}

void sw_srand(long seed){

  srandom(seed);

}

void sw_print_rand_info(){

  printf("[swarm] Random Genorator Info:\n");
  printf("[swarm]   Min=%lf  Max=%lf\n", _sw_rand_min, _sw_rand_max);

}
